import axiosInstance from '@/tools/request'
import type { WorkTravel } from '@/api/work/workTravel.d' // 这里时你将 work_travel.d.ts 存放的位置
import axios from 'axios'
import { responseDownload } from '@/tools/download'

//workTravelAdd 工作出差添加
export const workTravelAdd = (workTravel: WorkTravel) => {
  return axiosInstance({
    url: `/workTravel`,
    method: 'post',
    data: workTravel
  })
}

//workTravelRemove 工作出差删除
export const workTravelRemove = (workTravelId: number) => {
  return axiosInstance({
    url: `/workTravel/${ workTravelId }`,
    method: 'delete'
  })
}

//workTravelModify 工作出差修改
export const workTravelModify = (workTravel: WorkTravel) => {
  return axiosInstance({
    url: `/workTravel`,
    method: 'put',
    data: workTravel
  })
}

//workTravelList 工作出差列表
export const workTravelList = (workTravel:WorkTravel, params: any) => {
  return axiosInstance({
    url: '/workTravel/list',
    method: 'post',
    params: params,
    data: workTravel
  })
}

//workTravelById 工作出差查询通过ID
export const workTravelById = (workTravelId: number) => {
  return axiosInstance({
    url: `/workTravel/${ workTravelId }`,
    method: 'get'
  })
}


//workTravelRemoveBatch 工作出差批量删除
export const workTravelRemoveBatch = (ids: any[]) => {
  return axiosInstance({
    url: `/workTravel/batchDelete`,
    method: 'delete',
    params: {
      ids:ids
    }
  })
}

//workTravelBatchImportTemplateDownload ���作出差模板下载
export const workTravelBatchImportTemplateDownload = () => {
  axios({
    url: '/api/workTravel/templateDownload',
    method: 'get',
    responseType: 'blob',
    headers: {
      token: localStorage.getItem('token')
    }
  }).then(response => {
    responseDownload(response)
  })
}

//workTravelBatchExport ���作出差批量导出
export const workTravelBatchExport = (ids: any[]) => {
  axios({
    url: '/api/workTravel/export',
    method: 'get',
    responseType: 'blob',
    params: {
      ids: ids
    },
    headers: {
      token: localStorage.getItem('token')
    }
  }).then(response => {
    responseDownload(response)
  })

}

//workTravelRemoveBatch ���作出差批量导入
export const workTravelBatchImport = (file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  return axiosInstance({
    url: `/workTravel/import`,
    method: 'delete',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  })
}
